import { useMemo } from 'react'
import { useUrlQueryParam } from 'utils/url'

// 项目列表搜索参数
export const useProjectSearchParam = () => {
  const [param, setParam] = useUrlQueryParam(['name', 'personId'])
  return [
    useMemo(() => ({ ...param, personId: Number(param.personId) || undefined }), [param]),
    setParam,
  ] as const
}

export const useProjectModal = () => {
  const [{ projectCreate }, SetProjectCreate] = useUrlQueryParam(['projectCreate'])

  const open = () => SetProjectCreate({ projectCreate: true })
  const close = () => SetProjectCreate({ projectCreate: undefined })

  return { projectModalOpen: projectCreate === 'true', open, close }
}
